package com.example.wujinapi.controller;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.wujinapi.comm.R;
import com.example.wujinapi.entity.Swiperimgs;
import com.example.wujinapi.entity.wxDecryptPhoneUser;
import com.example.wujinapi.service.SwiperimgsService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * (Swiperimgs)表控制层
 *
 * @author makejava
 * @since 2023-08-25 19:06:34
 */
@RestController
@RequestMapping("swiperimgs")
public class SwiperimgsController{
    /**
     * 服务对象
     */
    @Resource
    private SwiperimgsService swiperimgsService;


    /**
     * 添加轮播图图片
     */
    @PostMapping("/addSwiperImgs")
    public R addSwiperImgs(@RequestBody Swiperimgs swiperimgs) throws Exception {
        //System.out.println("接收解密参数："+datas);
        if(swiperimgs.getToken()==null){
            return R.error(404,"无权限调用该接口");
        }
        try {
            swiperimgsService.addSwiperimgs(swiperimgs);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error(404,"添加轮播图错误"+e.getMessage());
        }
        return R.ok("添加轮播图成功");
    }



    /**
     * 添加轮播图图片
     */
    @PostMapping("/updateSwiperImgs")
    public R updateSwiperImgs(@RequestBody Swiperimgs swiperimgs) throws Exception {
        //System.out.println("接收解密参数："+datas);
        if(swiperimgs.getToken()==null){
            return R.error(404,"无权限调用该接口");
        }
        try {
            swiperimgsService.updateSwiperimgs(swiperimgs);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error(404,"更新轮播图错误"+e.getMessage());
        }
        return R.ok("更新轮播图成功");
    }



    /**
     * 删除某轮播图
     */
    @PostMapping("/deleteSwiperImgs")
    public R deleteSwiperImgs(@RequestBody Swiperimgs swiperimgs) throws Exception {
        //System.out.println("接收解密参数："+datas);
        if(swiperimgs.getToken()==null){
            return R.error(404,"无权限调用该接口");
        }
        try {
            swiperimgsService.deleteSwiperimgs(swiperimgs.getId());
        } catch (Exception e) {
            e.printStackTrace();
            return R.error(404,"删除轮播图错误"+e.getMessage());
        }
        return R.ok("删除轮播图成功");
    }




    /**
     * 获取所有轮播图
     */
    @PostMapping("/getSwiperImgsList")
    public R getSwiperImgsList() throws Exception {
        try {
            List<Swiperimgs> getSwiperimgsList =swiperimgsService.getSwiperimgs();
            return R.ok("获取轮播图成功").put("SwiperimgsList",getSwiperimgsList);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error(404,"获取轮播图错误"+e.getMessage());
        }
    }





} // Class End

